\defmodule {BernoulliGen}

This class implements random variate generators for the 
{\em Bernoulli\/} distribution (see class
 \externalclass{umontreal.iro.lecuyer.probdist}{BernoulliDist}).


 
\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        BernoulliGen
 * Description:  random variate generators for the Bernoulli distribution
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       Richard Simard
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.randvar;\begin{hide}
import umontreal.iro.lecuyer.probdist.BernoulliDist;
import umontreal.iro.lecuyer.rng.RandomStream;\end{hide}

public class BernoulliGen extends RandomVariateGenInt \begin{hide} {
   protected double p;    
    
\end{hide}\end{code}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {Constructors}
\begin{code}

   public BernoulliGen (RandomStream s, double p)\begin{hide} {
      super (s, new BernoulliDist (p));
      setParams (p);
   }\end{hide}
\end{code}
  \begin{tabb}
  Creates a Bernoulli random variate generator with parameter $p$,
  using stream \texttt{s}.
 \end{tabb}
\begin{code}

   public BernoulliGen (RandomStream s, BernoulliDist dist) \begin{hide} {
      super (s, dist);
      if (dist != null)
         setParams (dist.getP());
   }\end{hide}
\end{code}
  \begin{tabb} Creates a random variate generator for the {\em Bernoulli\/} 
    distribution \texttt{dist} and the random stream \texttt{s}. 
 \end{tabb}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {Methods}
\begin{code}

   public static int nextInt (RandomStream s, double p)\begin{hide} {
      return BernoulliDist.inverseF (p, s.nextDouble());
   }\end{hide}
\end{code}
\begin{tabb}
   Generates a new integer from the {\em Bernoulli\/} distribution with
  parameter $p = $~\texttt{p}, using the given stream \texttt{s}.
\end{tabb}
\begin{code}

   public double getP()\begin{hide} {
      return p;
   }
   \end{hide}
\end{code}
\begin{tabb} Returns the parameter $p$ of this object.
\end{tabb}
\begin{hide}\begin{code}

   protected void setParams (double p) {
      if (p < 0.0 || p > 1.0)
         throw new IllegalArgumentException ("p not in range [0, 1]");
      this.p = p;
   }
\end{code}
\begin{tabb} Sets the parameter $p$ of this object.
\end{tabb}
\begin{code}
}
\end{code}
\end{hide}
